﻿using DevExpress.Utils.Extensions;
using DevExpress.Utils.Filtering.Internal;
using Marmat.Foundation;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 测试项目
{
    public class PermissionManager : IPermissionManager
    {
        public void AddAdminUserCollection(string[] user_ids)
        {
        }

        public void AddDefaultPermissionCollection(string[] permission_ids)
        {
        }

        public void AddRolePermissionCollection(string role_id, string[] permission_ids)
        {
        }

        public void AddRoleUserCollection(string role_id, string[] user_ids)
        {
        }

        public IRoleEntity CreateRole(string parentName, string roleName)
        {
            return new RoleEntity { Parent = parentName, Text = roleName, Name = roleName };
        }

        public IRoleEntity CreateRoleGroup(string groupName)
        {
            return new RoleEntity { Name = groupName, IsGroup = true };
        }

        public void DeleteRole(string[] role_ids)
        {
        }

        public IEnumerable<IUserEntity> GetAdminUserCollection()
        {
            yield return new UserEntity() { UserID = "admin" };
        }

        public IEnumerable<IPermissionEntity> GetDefaultUserPermissionCollection()
        {
            foreach (var model in new string[] { "采购/采购订单", "销售/销售订单", "财务/财务主管" })
            {
                foreach (var item in new string[] { "新增", "编辑", "删除", "查询" })
                {
                    yield return new PermissionEntity() { Path = model, Name = item, Text = item };
                }
            }
        }

        public IEnumerable<IPermissionEntity> GetPermissionCollection()
        {
            foreach (var model in new string[] { "采购/采购订单", "销售/销售订单", "财务/财务主管" })
            {
                foreach (var item in new string[] { "新增", "编辑", "删除", "查询", "归档" })
                {
                    yield return new PermissionEntity() { Path = model, Name = item, Text = item };
                }
            }
        }

        public IEnumerable<IRoleEntity> GetRoleCollection()
        {
            yield return new RoleEntity() { Text = "职务", Name = "职务", IsGroup = true };
            yield return new RoleEntity() { Text = "财务", Name = "财务", Parent = "职务" };
            yield return new RoleEntity() { Text = "人事", Name = "人事", Parent = "职务" };
            yield return new RoleEntity() { Text = "出纳", Name = "出纳", Parent = "职务" };
            yield return new RoleEntity() { Text = "经理", Name = "经理", Parent = "职务" };
            yield return new RoleEntity() { Text = "科长", Name = "科长", Parent = "职务" };
            yield return new RoleEntity() { Text = "部长", Name = "部长", Parent = "职务" };
            yield return new RoleEntity() { Text = "总监", Name = "总监", Parent = "职务" };
        }

        public IEnumerable<IPermissionEntity> GetRolePermissionCollection(string role_id)
        {
            foreach (var model in new string[] { "采购", "销售" })
            {
                foreach (var item in new string[] { "新增", "编辑", "查询" })
                {
                    yield return new PermissionEntity() { Path = model, Name = item, Text = item };
                }
            }
        }

        public IEnumerable<IUserEntity> GetRoleUserCollection(string role_id)
        {
            for (int i = 0; i < 10; i++)
            {
                yield return new UserEntity() { UserID = $"{role_id}-用户-{i}" };
            }
        }

        public void RemoveAdminUserCollection(string[] user_ids)
        {
        }

        public void RemoveDefaultPermissionCollection(string[] permission_ids)
        {
        }

        public void RemoveRolePermissionCollection(string role_id, string[] permission_ids)
        {
        }

        public void RemoveRoleUserCollection(string role_id, string[] user_ids)
        {
        }

        public void ReNameRole(string role_id, string roleName)
        {
        }
    }

    public class UserEntity : IUserEntity
    {
        public string UserID { get; set; }
        public string NickName { get; set; }
    }

    public class PermissionEntity : IPermissionEntity
    {
        public string Text { get; set; }
        public string Name { get; set; }
        public string Path { get; set; }
        public int Index { get; set; }
    }
}
